package com.demo.Controller;

import java.util.List;

import javax.ws.rs.DefaultValue;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.demo.entity.ScoreVo;
import com.demo.entity.Totalscore;
import com.demo.service.TotalScoreService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Controller
@RequestMapping("/TotalScore")
public class TotalScoreController {
	@Autowired
	private TotalScoreService totalScoreService;
	//查询成绩详情
	@RequestMapping(value="/findtotalscoreVo/{page}/{pageSize}")
	public @ResponseBody PageInfo<Totalscore> findtotalscoreVo(@PathVariable Integer pageSize,@PathVariable Integer page) throws Exception {
		
		PageHelper.startPage(page, pageSize);
		List<Totalscore> allTotalScoreVo = totalScoreService.AllTotalScoreVo();
		PageInfo<Totalscore> pageInfo = new PageInfo<Totalscore>(allTotalScoreVo);
		return pageInfo;
	}
	//查询成绩详情
	@RequestMapping(value="/findscoreVo/{pageNum}/{pageSize}")
	public @ResponseBody PageInfo<ScoreVo> findscoreVo(@PathVariable @DefaultValue("1") Integer pageNum , @PathVariable @DefaultValue("5") Integer pageSize) throws Exception {
		 
		PageHelper.startPage(pageNum, pageSize);
		List<ScoreVo> allTotalScoreVo = totalScoreService.selectAllScoreVo();
		PageInfo<ScoreVo> pageInfo = new PageInfo<ScoreVo>(allTotalScoreVo);
		for (ScoreVo totalscore : allTotalScoreVo) {
			System.out.println(totalscore);
		}
		return pageInfo;
	}
	//查询成绩表所有信息
	@RequestMapping(value="findtotalscore/{page}/{pageSize}")
	public @ResponseBody PageInfo<Totalscore> findtotalscore(@PathVariable Integer pageSize,@PathVariable Integer page) throws Exception {
		 
		PageHelper.startPage(page, pageSize);
		List<Totalscore> allTotalScoreVo = totalScoreService.selectAllTotalScore();
		PageInfo<Totalscore> pageInfo = new PageInfo<Totalscore>(allTotalScoreVo);
		for (Totalscore totalscore : allTotalScoreVo) {
			System.out.println(totalscore);
		}
		return pageInfo;
	}
	//根据id查询
	@RequestMapping(value="/findScoreById/{id}")
	public @ResponseBody Totalscore findScoreById(@PathVariable String id) throws Exception{
		
		Totalscore selectTotalScoreById = totalScoreService.selectTotalScoreById(id);
		
		return selectTotalScoreById;
	}
	//根据id删除 
	@RequestMapping(value="/deleteScoreById/{id}")
	public @ResponseBody String deleteScoreById(@PathVariable String id) throws Exception{
		
		int deleteTotalScoreById = totalScoreService.deleteTotalScoreById(id);
		
		if(deleteTotalScoreById>0)
			return "ok";
		else
			return "error";
	}
	//不更新主键
	@RequestMapping(value="/updateScoreById")
	public @ResponseBody String updateScoreById( Totalscore totalscore) throws Exception{
		int updateTotalScore = totalScoreService.updateTotalScore(totalscore);
		if(updateTotalScore>0)
			return "ok";
		else
			return "error";
	}
	//新增
	@RequestMapping(value="/addTotalScore")
	public @ResponseBody String addTotalScore( Totalscore totalscore) throws Exception{
		int addTotalScore = totalScoreService.addTotalScore(totalscore);
		if(addTotalScore>0)
			return "ok";
		else
			return "error";
	}
	//查询
	@RequestMapping(value="/findScoreVococ",method=RequestMethod.GET)
	public @ResponseBody PageInfo<ScoreVo> findScoreVoscoc(ScoreVo scoreVo , @DefaultValue("1") Integer pageNum,@DefaultValue("5") Integer pageSize) throws Exception{
		PageHelper.startPage(pageNum, pageSize);
		scoreVo.setSid(scoreVo.getSid().trim());
		scoreVo.setClassName(scoreVo.getClassName().trim());
		scoreVo.setCourseName(scoreVo.getCourseName().trim());
		scoreVo.setSname(scoreVo.getSname().trim());
		List<ScoreVo> findScoreVoscoc = totalScoreService.findScoreVoscoc(scoreVo);
		PageInfo<ScoreVo> pageInfo = new PageInfo<>(findScoreVoscoc);
		return pageInfo;
	}
}
